import { Component, OnInit } from '@angular/core';
import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';

@Component({
  selector: 'app-operator',
  templateUrl: './operator.component.html',
  styleUrls: ['./operator.component.css']
})

export class OperatorComponent implements OnInit {

  private headers = new Headers({'Content-Type': 'application/json'});
  
  constructor(
    private http: Http
  ) { }

  ngOnInit() {
    this.getAjaxData(1);
  }

  userData = {totalRecord: 0, data: []};
  userParam = {currentPage: 1, showRecord: 10};

  getAjaxData(pageNumber) {
    this.userParam.currentPage = pageNumber;
    this.http.post('/api/sys/operator/list', JSON.stringify(this.userParam), {headers: this.headers})
      .toPromise().then((response) => { this.userData = response.json() });
  }
}
